Fix: [zipplugin] Show password error.#309
Merged
deepin-bot[bot] merged 1 commit intolinuxdeepin:release/eaglefrom Aug 20, 2025
Merged
Fix: [zipplugin] Show password error.#309deepin-bot[bot] merged 1 commit intolinuxdeepin:release/eaglefrom
deepin-bot[bot] merged 1 commit intolinuxdeepin:release/eaglefrom
Conversation
-- When enter the right password, show password error. -- Not judge the Second password, so add code logic the adjust it. Log: fix issue Bug: https://pms.uniontech.com/bug-view-329305.html
deepin pr auto review我对这段代码进行审查,提供以下改进建议:
// 在类中定义最大密码尝试次数
static const int MAX_PASSWORD_ATTEMPTS = 3;
// 提取密码验证逻辑为单独函数
bool LibzipPlugin::handlePasswordError(zip_int64_t currentIndex, int& attemptCount) {
if (m_eErrorType != ET_WrongPassword && m_eErrorType != ET_NeedPassword) {
return false;
}
// 检查尝试次数
if (++attemptCount >= MAX_PASSWORD_ATTEMPTS) {
zip_close(archive);
m_strPassword = "";
return false;
}
// 如果是重复尝试同一文件且密码错误,直接返回
if (attemptCount > 1 && lastNeedPasswordIndex == currentIndex) {
zip_close(archive);
m_strPassword = "";
return false;
}
PasswordNeededQuery query(strFileName);
emit signalQuery(&query);
query.waitForResponse();
if (query.isAccepted()) {
setPassword(query.password());
zip_set_default_password(archive, m_strPassword.toUtf8().constData());
lastNeedPasswordIndex = currentIndex;
return true;
}
return false;
}
// 在extractFiles函数中使用
for (zip_int64_t i = 0; i < nofEntries; ++i) {
if (QThread::currentThread()->isInterruptionRequested()) {
// ... 现有代码 ...
}
int passwordAttempts = 0;
while (true) {
// ... 现有解压逻辑 ...
if (error) {
if (!handlePasswordError(i, passwordAttempts)) {
return PFT_Error;
}
continue; // 密码正确后重试当前文件
}
break;
}
}
这些改进建议旨在提高代码的可维护性、安全性和性能,同时保持原有功能不变。根据实际需求,可以选择实施部分或全部建议。 |
Reviewer's guide (collapsed on small PRs)Reviewer's GuideIn extractFiles, this PR refactors the password prompt flow to track and handle consecutive wrong-password attempts for the same archive entry, preventing false error signals when a correct password is supplied. Sequence diagram for improved password error handling in extractFilessequenceDiagram
participant Plugin as LibzipPlugin
participant Archive as zip archive
participant User as actor User
participant Query as PasswordNeededQuery
Plugin->>Archive: Attempt to extract entry[i]
alt Password required or wrong password
Plugin->>Query: Emit signalQuery for password
User->>Query: Enter password
Query->>Plugin: Return password
Plugin->>Archive: Set password and retry
alt Password still wrong for same entry
Plugin->>Archive: Close archive
Plugin->>User: Show password error
else Password correct
Plugin->>Archive: Continue extraction
end
else No password needed
Plugin->>Archive: Continue extraction
end
Class diagram for updated LibzipPlugin password handlingclassDiagram
class LibzipPlugin {
+extractFiles(files, options)
-m_eErrorType
-m_strPassword
-lastNeedPasswordIndex
}
class PasswordNeededQuery {
+password()
+waitForResponse()
}
LibzipPlugin "1" -- "*" PasswordNeededQuery: emits signalQuery
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
liyigang1
approved these changes
Aug 20, 2025
max-lvs
approved these changes
Aug 20, 2025
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: GongHeng2017, liyigang1, max-lvs The full list of commands accepted by this bot can be found here. DetailsNeeds approval from an approver in each of these files:Approvers can indicate their approval by writing |
Contributor
Author
|
/merge |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
-- When enter the right password, show password error. -- Not judge the Second password, so add code logic the adjust it.
Log: fix issue
Bug: https://pms.uniontech.com/bug-view-329305.html
Summary by Sourcery
Fix password error handling in libzip plugin to properly track and limit password retries
Bug Fixes:
Enhancements: